package com.whitedust.top70;

import com.whitedust.structure.TreeNode;

/**
 *
 * @author A
 * @since 2025/11/11 12:55
 */

public class Top65 {
    public boolean isSymmetric(TreeNode root) {
        return check(root.left, root.right);
    }

    private boolean check(TreeNode left, TreeNode right) {
        //左右均为空返回对称
        if (left == null && right == null) return true;
        //一个为空一个不为空返回不对称
        if (left == null || right == null) return false;
        //当左右子树的节点相等，且左子树的左节点等于右子树的右节点，且左子树的右节点等于右子树的左节点则对称
        return left.val == right.val && check(left.left, right.right) && check(left.right, right.left);
    }
}
